import { install } from 'source-map-support';
install();

import { program } from 'commander';
import fs from 'fs-extra';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const myPackage = await fs.readJSON(path.join(__dirname, '../package.json'));

import { FindUsage } from "./FindUsage.js";

interface CmdOption {
    projectRoot: string;
    fyConvertorRoot: string
}

const rmQuotes = (val: string): string => {
    let rst = val.match(/(['"])(.+)\1/);
    if(rst) return rst[2];

    return val;
}

program
	.version(myPackage.version, "-v, --version")
	.option("-p, --project-root <string>", "[MUST] project root.", rmQuotes)
	.option("-f, --fyConvertor-root <string>", "[MUST] fy-convertor temp root.", rmQuotes)
    .parse(process.argv);

let opts = program.opts() as CmdOption;
console.log(`cmd options: ${JSON.stringify(opts)}`);

const fu = new FindUsage();
await fu.startFind(opts.projectRoot, opts.fyConvertorRoot);
